﻿using System;
using System.Management.Automation;
using DotNet.DevOps.Tasks.Util;

namespace DotNet.DevOps.Cmdlets
{
    class PowershellCmdletLogger : ILogger
    {
        private Cmdlet cmdlet;

        public PowershellCmdletLogger(Cmdlet cmdlet)
        {
            this.cmdlet = cmdlet;
        }

        public void LogInfo(string msg)
        {
            cmdlet.WriteCommandDetail(msg);
        }

        public void LogWarning(string msg)
        {
            cmdlet.WriteWarning(msg);
        }

        public void LogError(Exception exception)
        {
            cmdlet.WriteError(new ErrorRecord(exception, "Error", ErrorCategory.InvalidData, cmdlet));
        }
    }
}
